package com.hutu.core.constant;

import com.hutu.model.dto.vo.system.EntityVo;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 数据字典
 */
public class SelectConstant {
    public static final Map<String, Set<EntityVo>> selectMap = new HashMap<>();

    // 注册下拉选数据
    static  {

    }

    private static <T> void register(String key, T[] ts, Function<T,String> name, Function<T,String> value){
        //改成按照code升序排序
        Set<EntityVo> voSet = Arrays.stream(ts).map(t->convert(t,name,value)).collect(Collectors.toCollection(LinkedHashSet::new));
        selectMap.put(key,voSet);
    }

    private static <T> EntityVo convert(T t, Function<T,String> code,Function<T,String> message){
        EntityVo vo = new EntityVo();
        vo.setId(code.apply(t));
        vo.setName(message.apply(t));
        return vo;
    }
}
